#include "MainEngine.h"

#include "Standard.h"

#include "../Object/ObjectManager.h"
#include "../Event/EventSystem.h"
#include "../Scene/SceneSystem.h"
#include "../Input/InputSystem.h"
#include "../Time/ClockSystem.h"

#include "../Time/Timer.h"

#include "../Console/ConsoleWindow.h"


////////////////////////////////////////////////////////////////////////////////////////////////////
/// <Summary>	Initializes all the internal objects </Summary>
////////////////////////////////////////////////////////////////////////////////////////////////////
void MainEngine::Initialize()
{
	SceneSystem::GetInstance().Initialize();
	EventSystem::GetInstance().Initialize();
	InputSystem::GetInstance().Initialize();

	ClockSystem::GetInstance();
	ConsoleWindow::GetInstance();

	SceneSystem::GetInstance().RegisterScene<TestScene>(TestScene::SCENEID);
	EventSystem::GetInstance().RegisterEvent<TestEvent>(TestEvent::EVENTID);
}

////////////////////////////////////////////////////////////////////////////////////////////////////
/// <Summary>	Shuts down the engine and all internal objects </Summary>
////////////////////////////////////////////////////////////////////////////////////////////////////
void MainEngine::Shutdown()
{
	SceneSystem::GetInstance().Shutdown();
	EventSystem::GetInstance().Shutdown();
	InputSystem::GetInstance().Shutdown();

	SceneSystem::DeleteInstance();
	EventSystem::DeleteInstance();
	InputSystem::DeleteInstance();
	ClockSystem::DeleteInstance();
	ConsoleWindow::DeleteInstance();
}



////////////////////////////////////////////////////////////////////////////////////////////////////
/// <Summary>	Updates the engine </Summary>
////////////////////////////////////////////////////////////////////////////////////////////////////
void MainEngine::Update()
{
	if(InputSystem::GetInstance().KeyPressed(VK_ESCAPE))
		PostQuitMessage(0);

	ClockSystem::GetInstance().FrameStart();
	
	SceneSystem::GetInstance().Update(ClockSystem::GetInstance().GetDeltaTimeF());

	EventSystem::GetInstance().Update(ClockSystem::GetInstance().GetDeltaTimeF());

	SceneSystem::GetInstance().Render(ClockSystem::GetInstance().GetDeltaTimeF());

	InputSystem::GetInstance().FrameUpdate();

	ClockSystem::GetInstance().FrameEnd();
}